-- Decompiled with the Synapse X Luau decompiler.

local l__CommonOHOH__1 = _G.CommonOHOH;
local v2 = {};
local l__assert__1 = assert;
local l__ipairs__2 = ipairs;
function v2.GetTrack(p1, p2)
	l__assert__1(p2, "param name is nil");
	local v3 = p1.animations[p2];
	l__assert__1(v3, "no animation info for " .. p2);
	local v4 = l__CommonOHOH__1:Random(1, v3.weight);
	for v5, v6 in l__ipairs__2(v3.tracks) do
		v4 = v4 - v6.weight;
		if v4 <= 0 then
			return v6.track;
		end;
	end;
end;
function v2.SwitchBaseAnimate(p3, p4)
	local v7 = nil;
	if p3.__current_base_animation then
		v7 = p3.__current_base_animation.name;
	end;
	if v7 ~= p4 then
		if v7 then
			p3:Stop(v7);
		end;
		p3:Play(p4);
		p3.__current_base_animation = p3.__action_animtions[p4];
		if p3.__current_tool_hold then
			p3:Play(p3.__current_tool_hold);
		end;
	end;
end;
function v2.SetBaseAnimateSpeed(p5, p6)
	if p5.__current_base_animation then
		p5:SetSpeed(p5.__current_base_animation.name, p6);
	end;
end;
function v2.OnRunning(p7, p8)
	if p8 == 0 then
		v2.SwitchBaseAnimate(p7, "idle");
		return;
	end;
	if p8 <= 8 then
		v2.SwitchBaseAnimate(p7, "walk");
		v2.SetBaseAnimateSpeed(p7, p8 / 8);
		return;
	end;
	v2.SwitchBaseAnimate(p7, "run");
	v2.SetBaseAnimateSpeed(p7, p8 / 16);
end;
function v2.OnJumping(p9, p10)
	if p10 then
		v2.SwitchBaseAnimate(p9, "jump");
	end;
end;
function v2.OnClimbing(p11, p12)
	v2.SwitchBaseAnimate(p11, "climb");
	v2.SetBaseAnimateSpeed(p11, p12 / 16);
end;
function v2.OnFallingDown(p13, p14)
	if p14 then
		v2.SwitchBaseAnimate(p13, "fall");
	end;
end;
function v2.OnFreeFall(p15, p16)
	if p16 then
		v2.SwitchBaseAnimate(p15, "fall");
	end;
end;
function v2.OnSeated(p17, p18, p19)
	if p18 then
		v2.SwitchBaseAnimate(p17, "sit");
	end;
end;
function v2.OnSwimming(p20, p21)
	if p21 <= 0 then
		v2.SwitchBaseAnimate(p20, "swimidle");
		return;
	end;
	v2.SwitchBaseAnimate(p20, "swim");
	v2.SetBaseAnimateSpeed(p20, p21 / 16);
end;
function v2.OnDied(p22)
	p22:StopAllAnimation();
end;
function v2.OnGettingUp(p23, p24, p25)
	if p25 then
		p24:StopAllAnimation();
	end;
end;
function v2.OnPlatformStanding(p26, p27)
	if p27 then
		p26:StopAllAnimation();
	end;
end;
function v2.OnHoldTool(p28, p29, p30)
	if p29 then
		if not p30 or not p30:FindFirstChild("Handle") then
			return;
		end;
	else
		p28:UninstallAnimation("new_tool_hold");
		p28:UninstallAnimation("new_tool_action");
		p28:Stop(p28.__current_tool_hold);
		p28.__current_tool_hold = nil;
		p28.__current_tool_action = nil;
		return;
	end;
	local l__tool_hold__8 = p30:FindFirstChild("tool_hold");
	if l__tool_hold__8 then
		p28:UninstallAnimation("new_tool_hold");
		p28.animations.new_tool_hold = p28:LoadAnimationWithInst(l__tool_hold__8);
		if #p28.animations.new_tool_hold.tracks == 0 then
			p28.animations.new_tool_hold = nil;
		end;
	end;
	local l__tool_action__9 = p30:FindFirstChild("tool_action");
	if l__tool_action__9 then
		p28:UninstallAnimation("new_tool_action");
		p28.animations.new_tool_action = p28:LoadAnimationWithInst(l__tool_action__9);
		if #p28.animations.new_tool_action == 0 then
			p28.animations.new_tool_action = nil;
		end;
	end;
	local v10 = "new_tool_hold";
	if p28.animations.new_tool_hold then
		v10 = "new_tool_hold";
	else
		v10 = "tool_hold";
	end;
	p28.__current_tool_hold = v10;
	local v11 = "new_tool_action";
	if p28.animations.new_tool_action then
		local v11 = "new_tool_action";
	else
		v11 = "tool_action";
	end;
	p28.__current_tool_action = v11;
	p28:Play(p28.__current_tool_hold);
end;
function v2.OnToolAction(p31, p32)

end;
function v2.LinkStates(p33)
	local v12 = p33.parent:GetHumanoid_Check();
	p33.__state_rbxs = {};
	p33.__state_rbxs.died = v12.Died:Connect(function()
		v2.OnDied(p33);
	end);
	p33.__state_rbxs.running = v12.Running:Connect(function(p34)
		v2.OnRunning(p33, p34);
	end);
	p33.__state_rbxs.jumping = v12.Jumping:Connect(function(p35)
		v2.OnJumping(p33, p35);
	end);
	p33.__state_rbxs.climbing = v12.Climbing:Connect(function(p36)
		v2.OnClimbing(p33, p36);
	end);
	p33.__state_rbxs.getting_up = v12.GettingUp:Connect(function(p37)
		v2.OnGettingUp(p33, p37);
	end);
	p33.__state_rbxs.free_falling = v12.FreeFalling:Connect(function(p38)
		v2.OnFreeFall(p33, p38);
	end);
	p33.__state_rbxs.falling_down = v12.FallingDown:Connect(function()
		v2.OnFallingDown(p33);
	end);
	p33.__state_rbxs.seated = v12.Seated:Connect(function(p39, p40)
		v2.OnSeated(p33, p39, p40);
	end);
	p33.__state_rbxs.platform_standing = v12.PlatformStanding:Connect(function(p41)
		v2.OnPlatformStanding(p33);
	end);
	p33.__state_rbxs.swimming = v12.Swimming:Connect(function(p42)
		v2.OnSwimming(p33, p42);
	end);
	p33.__state_rbxs.tool_add = p33.parent.main_inst.ChildAdded:Connect(function(p43)
		if p43:IsA("Tool") then
			v2.OnHoldTool(p33, true, p43);
		end;
	end);
	p33.__state_rbxs.tool_remove = p33.parent.main_inst.ChildRemoved:Connect(function(p44)
		local v13 = nil;
		if p44:IsA("Tool") then
			v13 = p33.parent.main_inst:FindFirstAncestorOfClass("Tool");
			if not v13 then
				v2.OnHoldTool(p33, false);
				return;
			end;
		else
			return;
		end;
		v2.OnHoldTool(p33, true, v13);
	end);
end;
function v2.DelHandleOnDidLoop(p45, p46)
	local v14 = p45.animations[p46.name];
	if v14 then
		local l__on_did_loop__15 = v14.on_did_loop;
		if l__on_did_loop__15 then
			l__on_did_loop__15[p46.handle] = nil;
		end;
	end;
end;
function v2.HandleOnDidLoopExist(p47, p48)
	local v16 = nil;
	local v17 = p47.animations[p48.name];
	if v17 then
		v16 = v17.on_did_loop;
		if not v16 then
			return;
		end;
	else
		return;
	end;
	return v16[p48.handle];
end;
function v2.DelHandleOnStopped(p49, p50)
	local v18 = p49.animations[p50.name];
	if v18 then
		local l__on_stopped__19 = v18.on_stopped;
		if l__on_stopped__19 then
			l__on_stopped__19[p50.handle] = nil;
		end;
	end;
end;
function v2.HandleOnStoppedExist(p51, p52)
	local v20 = nil;
	local v21 = p51.animations[p52.name];
	if v21 then
		v20 = v21.on_stopped;
		if not v20 then
			return;
		end;
	else
		return;
	end;
	return v20[p52.handle];
end;
function v2.DelHandleOnMark(p53, p54)
	local v22 = p53.animations[p54.name];
	if v22 then
		local l__on_mark__23 = v22.on_mark;
		if l__on_mark__23 then
			local v24 = l__on_mark__23[p54.mark];
			if v24 then
				v24[p54.handle] = nil;
			end;
		end;
	end;
end;
function v2.HandleOnMarkExist(p55, p56)
	local v25 = nil;
	local v26 = p55.animations[p56.name];
	if v26 then
		local l__on_mark__27 = v26.on_mark;
		if l__on_mark__27 then
			v25 = l__on_mark__27[p56.mark];
			if not v25 then
				return;
			end;
		else
			return;
		end;
	else
		return;
	end;
	return v25[p56.handle];
end;
local l__pairs__3 = pairs;
function v2.Play(p57, p58, p59, p60, p61)
	p57.__action_animtions[p58] = p57.__action_animtions[p58] or {
		name = p58, 
		rbxs = {}, 
		speed = p60, 
		action_time = p61
	};
	local v28 = p57.__action_animtions[p58];
	if v28.track == p59 and p59.IsPlaying then
		return;
	end;
	p60 = p60 or (v28.speed or 1);
	p61 = p61 or v28.action_time;
	if v28.track and v28.track.IsPlaying then
		v28.track:Stop(0.1);
	end;
	for v29, v30 in l__pairs__3(v28.rbxs) do
		v30:Disconnect();
		v28.rbxs[v29] = nil;
	end;
	v28.track = p59;
	if p59.Looped and #p57.animations[p58].tracks > 1 then
		v28.rbxs.did_loop = p59.DidLoop:Connect(function()
			p57:Play(p58, p59.Speed);
		end);
	end;
	local v31 = p57.animations[p58];
	if v31.on_did_loop then
		for v32, v33 in l__pairs__3(v31.on_did_loop) do
			v28.rbxs[v32] = p59.DidLoop:Connect(function()
				v32(p57.parent);
			end);
		end;
	end;
	if v31.on_stopped then
		for v34, v35 in l__pairs__3(v31.on_stopped) do
			v28.rbxs[v34] = p59.Stopped.Connect(function()
				v34(p57.parent);
			end);
		end;
	end;
	if v31.on_mark then
		for v36, v37 in l__pairs__3(v31.on_mark) do
			for v38, v39 in l__pairs__3(v37) do
				local v40 = p59:GetMarkerReachedSignal(v36):Connect(function()
					v38(p57.parent);
				end);
				v28.rbxs[v40] = v40;
			end;
		end;
	end;
	p59:Play(0.1);
	if p61 then
		p60 = p59.Length / p61;
	end;
	p59:AdjustSpeed(p60);
	return p59;
end;
local u4 = l__CommonOHOH__1.class.new(script, l__CommonOHOH__1.files.BaseComponent());
function u4.new(p62)
	return u4(p62);
end;
local l__Instance__5 = Instance;
function u4.ctor(p63, p64)
	u4.super.ctor(p63, p64);
	local v41 = l__Instance__5.new("Folder", p64.main_inst);
	v41.Name = "CharacterAnimationComponent";
	p63:SetMainInst(v41);
	p63.__action_animtions = {};
end;
function u4.dtor(p65)
	u4.super.dtor(p65);
end;
function u4.UninstallAnimation(p66, p67)
	local v42 = p66.animations[p67];
	if v42 then
		for v43, v44 in l__ipairs__2(v42.tracks) do
			if v44.track.IsPlaying then
				v44.track:Stop();
			end;
			v44.track:Destroy();
		end;
		p66.animations[p67] = nil;
	end;
end;
local l__table__6 = table;
function u4.LoadAnimationWithInst(p68, p69)
	local v45 = p68.parent:GetHumanoid_Check();
	local v46 = {
		tracks = {}, 
		weight = 0
	};
	for v47, v48 in l__ipairs__2(p69:GetDescendants()) do
		if v48:IsA("Animation") then
			local v49 = v48:FindFirstChild("weight");
			if not v49:IsA("NumberValue") then
				v49 = nil;
			end;
			v46.weight = v46.weight + (v49 and v49.Value or 1);
			l__table__6.insert(v46.tracks, {
				track = v45:LoadAnimation(v48), 
				weight = v46.weight
			});
		end;
	end;
	return v46;
end;
local l__tostring__7 = tostring;
function u4.LoadAnimationsWithConfig(p70, p71)
	if not p70.parent.main_inst.Parent then
		p70.parent:AddHandleOnInWorkspace(function()
			p70:LoadAnimationsWithConfig(p71);
		end, true);
		return;
	end;
	local v50 = p70.parent:GetHumanoid_Check();
	local v51 = {};
	local v52 = l__Instance__5.new("Folder", p70.main_inst);
	v52.Name = "config_animates";
	p70.animate_folder = v52;
	for v53, v54 in l__pairs__3(p71) do
		v51[v53] = {};
		v51[v53].weight = 0;
		v51[v53].tracks = {};
		local v55 = l__Instance__5.new("StringValue", p70.animate_folder);
		v55.Name = v53;
		for v56, v57 in l__ipairs__2(v54) do
			v51[v53].weight = v51[v53].weight + v57.weight;
			local v58 = v53 .. l__tostring__7(v56);
			local v59 = l__Instance__5.new("Animation", v55);
			v59.Name = v58;
			v59.AnimationId = v57.id;
			local v60 = l__Instance__5.new("NumberValue", v59);
			v60.Name = "weight";
			v60.Value = v57.weight;
			local v61 = v50:LoadAnimation(v59);
			v61.Name = v58;
			l__table__6.insert(v51[v53].tracks, {
				track = v61, 
				weight = v57.weight
			});
		end;
	end;
	p70.animations = v51;
	v2.LinkStates(p70);
end;
function u4.StopAllAnimation(p72)
	for v62, v63 in l__ipairs__2(p72.parent:GetHumanoid_Check():GetPlayingAnimationTracks()) do
		v63:Stop();
	end;
end;
function u4.Play(p73, p74, p75, p76)
	local v64 = nil;
	if p73.animations[p74] then
		v64 = v2.GetTrack(p73, p74);
		if not v64 then
			return;
		end;
	else
		return;
	end;
	return v2.Play(p73, p74, v64, p75, p76);
end;
function u4.SetSpeed(p77, p78, p79)
	p79 = p79 and 1;
	local l__track__65 = (p77.__action_animtions[p78] or {
		rbxs = {}, 
		name = p78, 
		speed = p79
	}).track;
	if l__track__65 then
		l__track__65:AdjustSpeed(p79);
	end;
end;
function u4.Stop(p80, p81)
	local l__track__66 = (p80.__action_animtions[p81] or {
		rbxs = {}, 
		name = p81
	}).track;
	if l__track__66 and l__track__66.IsPlaying then
		l__track__66:Stop(0.1);
	end;
end;
function u4.Pause(p82, p83)
	local l__track__67 = (p82.__action_animtions[p83] or {
		rbxs = {}, 
		name = p83
	}).track;
	if l__track__67 and l__track__67.IsPlaying then
		l__track__67:AdjustSpeed(0);
	end;
end;
function u4.IsPlaying(p84, p85)
	local v68 = nil;
	local v69 = p84.action_animation[p85];
	if v69 then
		v68 = v69.track;
		if not v68 then
			return;
		end;
	else
		return;
	end;
	return v68.IsPlaying;
end;
return u4;
